#ifndef BUFFER_IPC_H
#define BUFFER_IPC_H

#include "../../Thrift/Client/NodeClient.h"
#include <ClientSub.hpp>
#include <deque>
#include <map>
#include <memory>
#include <string>
#include <thrift/protocol/TBinaryProtocol.h>
#include <thrift/protocol/TProtocol.h>
#include <thrift/transport/TSocket.h>
#include <thrift/transport/TTransport.h>
#include <thrift/transport/TTransportUtils.h>

class DeviceObj;

class BufferIPC {
  std::map<std::string, DeviceObj *> DeviceList;
  std::shared_ptr<apache::thrift::transport::TTransport> socket, transport;
  std::shared_ptr<apache::thrift::protocol::TProtocol> protocol;
  Thrift::NodeClientClient *client = nullptr;
  ClientSub broadcast;

public:
  BufferIPC();
  virtual ~BufferIPC();
  /**
   * @brief 启动IPC服务
   *
   * @param addr Client实例地址
   * @param port Client端口
   */
  void Boot(std::string addr, long clientport, long broadcastPort);
  /**
   * @brief 获取设备列表
   * @return 设备UUID列表
   */
  std::deque<std::string> GetDeviceList();
  /**
   * @brief 获取设备
   *
   * @return
   * DeviceObj对象,所有权依然为BufferIPC所有,如果没有找到设备将返回Nullptr
   */
  DeviceObj *GetDevice(const std::string &UUID);
};

#endif
